package com.Drools.CIPS.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;

/**
 * 工具类
 */
public class XmlMapUtil {
    public static void main(String[] args) {
        System.out.println(ActiveOrHistoricCurrency("CNY1"));
    }
    public static Object getValue(Object map,String s){

        for (String s1:s.split("\\.")){
            if(map == null){
                return null;
            }
            map = ((Map) map).get(s1);
        }
        return map;
    }

    /**
     * 获取活动货币
     * @param key
     * @return
     */
    private static String ActiveCurrency(String key) {
        Properties properties = new Properties();
        //Hashtable的子类 常用来处理配置文件   key-value都是String
        try(FileReader fis = new FileReader("src/main/resources/ISO4217.properties");) {

            properties.load(fis);//加载对应的文件
           return properties.getProperty(key);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 历史货币
     * @param key
     * @return
     */
    private static String HistoricCurrency(String key) {
        Properties properties = new Properties();
        //Hashtable的子类 常用来处理配置文件   key-value都是String
        try(FileReader fis = new FileReader("src/main/resources/hisISO4217.properties");) {

            properties.load(fis);//加载对应的文件
           return properties.getProperty(key);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 活动或历史货币
     * @param key
     * @return
     */
    private static String ActiveOrHistoricCurrency(String key) {
        String s = ActiveCurrency(key);
        if(s == null){
            s = HistoricCurrency(key);
        }
        return s;
    }

}
